added options to send plain or html emails

Judy Ngai 8 years ago
parent
commit
d7f46f77e4
2 changed files with 11 additions and 1 deletions
  1. 8 1
      app/mailers/system_mailer.rb
  2. 3 0
      app/models/agents/email_agent.rb

+ 8 - 1
app/mailers/system_mailer.rb

@@ -8,6 +8,13 @@ class SystemMailer < ActionMailer::Base
8 8
 
9 9
     mail_options = { to: options[:to], subject: options[:subject] }
10 10
     mail_options[:from] = options[:from] if options[:from].present?
11
-    mail(mail_options)
11
+    if options[:content_type].present?
12
+      mail(mail_options) do |format|
13
+        format.text if options[:content_type] == "text/plain"
14
+        format.html if options[:content_type] == "text/html"
15
+      end
16
+    else
17
+      mail(mail_options)
18
+    end
12 19
   end
13 20
 end

+ 3 - 0
app/models/agents/email_agent.rb

@@ -23,6 +23,8 @@ module Agents
23 23
 
24 24
       You can provide a `from` address for the email, or leave it blank to default to the value of `EMAIL_FROM_ADDRESS` (`#{ENV['EMAIL_FROM_ADDRESS']}`).
25 25
 
26
+      You can provide a `content_type` for the email and specify `text/plain` or `text/html` to be sent.
27
+
26 28
       Set `expected_receive_period_in_days` to the maximum amount of time that you'd expect to pass between Events being received by this Agent.
27 29
     MD
28 30
 
@@ -44,6 +46,7 @@ module Agents
44 46
             subject: interpolated(event)['subject'],
45 47
             headline: interpolated(event)['headline'],
46 48
             body: interpolated(event)['body'],
49
+            content_type: interpolated(event)['content_type'],
47 50
             groups: [present(event.payload)]
48 51
           ).deliver_later
49 52
         end